//
//  AIFLoginManager.m
//  PywSdk
//
//  Created by liangyidong on 16/1/26.
//  Copyright © 2016年 zero. All rights reserved.
//

#import "AIFLoginManager.h"
#import "PywUser.h"
#import "ApiClient.h"
#import "PywRSAUtil.h"

@implementation AIFLoginManager

NSString *const Login_USERNAME = @"username";
NSString *const Login_TID = @"tid";
NSString *const Login_GAMEID = @"gameid";
NSString *const Login_SIGN = @"sign";
NSString *const Login_PASSWORD = @"password";

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.child = self;
        self.paramSource = self;
        self.validate = self;
    }
    return self;
}


#pragma mark - ETAPIManager
- (NSString *)methodName{
    return URL_LOGIN;
}

- (ETAPIManagerRequestType)requestType{
    return ETAPIManagerRequestTypePost;
}

- (NSString *)seriviceType{
    return [PywAppInfo sharedAppInfo].seriviceType;
}


#pragma mark - ETAPIManagerParamSourceDelegate
- (NSDictionary *)paramsForApi:(ETApiBaseManager *)manager{
    
    //流水号
    NSString *tid = [[PywAppInfo sharedAppInfo] tid];
    NSString * gameid = [PywAppInfo sharedAppInfo].gameId;
    if (gameid.length == 0) {
        return nil;
    }
    NSString * apiSecret2 = [AppUtil getApiSecret2:tid apiSecret:[PywAppInfo sharedAppInfo].apisecret];
    NSString *sign = [NSString stringWithFormat:@"%@%@%@", gameid,
                           self.passport, apiSecret2];
    sign = [PywCipherUtils md5:sign];
    
    MutableDictionary *param = [[MutableDictionary alloc] init];
    NSString *rsaPassPort = [self.passport debugDescription];
    [param setObject:rsaPassPort forKey:Login_USERNAME];
    [param setObject:tid forKey:Login_TID];
    [param setObject:gameid forKey:Login_GAMEID];
    [param setObject:sign forKey:Login_SIGN];
    
    NSString * pwd = self.password;
    if (self.isEncryptRSA) {
        pwd = [PywRSAUtil encryptString:self.password];
    }
    [param setObject:pwd forKey:Login_PASSWORD];
    return param;
}



#pragma mark - ETAPIManagerValidator
- (BOOL)manager:(ETApiBaseManager *)manager isCorrectWithParamsData:(NSDictionary *)data{
    return YES;
}

- (BOOL)manager:(ETApiBaseManager *)manager isCorrectWithCallBackData:(NSDictionary *)data{
    return YES;
}

@end
